<include file="Public/min-header"/>
<div class="wrapper">
  <include file="Public/breadcrumb"/>
<style>
	  #fenlei_box{border: 1px solid #3297ff;position: absolute;width:450px;height:250px;overflow:hidden; z-index:9999;background:#fff;display:none;}
	  #fenlei_box li{list-style: none;color:#3297ff;text-align:left;margin-left:-20px;line-height: 32px;cursor: pointer;border-bottom:1px dashed}
	  #teshu{display: none;color:red;}
	  @media screen and (max-width: 767px) {
            .col-xs-4 {
                width: 100%;
            }
            .col-xs-2{
                width: 100%;
            }
            .col-xs-5{
                width: 100%;
            }
            .col-xs-8 {
                width: 100%;
            }
           
        }

</style>
    <section class="content">
        <!-- Main content --> 
        <div class="container-fluid">
            <div class="pull-right">
                <a href="javascript:history.go(-1)" data-toggle="tooltip" title="" class="btn btn-default" data-original-title="返回"><i class="fa fa-reply"></i></a>
            </div>
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h3 class="panel-title"><i class="fa fa-list"></i>订单基本信息</h3>
                </div>
                <div class="panel-body">
<!-- <span style="color: red;">此功能升级中，请稍候再试。。。</span> -->
                    <!--表单数据-->
                    <form method="post" action="{:U('Order/add_order')}" id="order-add">
                        <div class="tab-pane" >
                            <table class="table table-bordered">
                                <tbody>
                                <tr>
                                    <td width="110">下单类型:</td>
                                    <td>
	                                   <label><input name="dai_type" id="dai_type" type="radio" checked="checked" value="0"/> 普通线上单</label>
									<?php
									if($_SESSION['admin_id'] || session('store_id')=='43' || session('store_id')=='44' || session('store_id')=='46' || session('store_id')=='48' || session('store_id')=='49' || session('store_id')=='53'){
									?>
									  <!-- <label><input name="dai_type" id="dai_type" type="radio" value="2" style="margin-left:10px;"/> 特殊线下单</label><span style="color:red;">(线下私有客户)</span> -->
									   <?php
									   }
									   ?>
                                    </td>
                                </tr>
									<tr>
                                    <td>会员客户:</td>
                                    <td>
                                    <div class="form-group ">
                                        <div class="col-xs-4">
                                            <input name="user_name" id="user_name" class="form-control" value="" placeholder="客户公司名/手机号码搜索" oninput="kehu_sousuo($(this))" autocomplete="off"/>
			<ul id="fenlei_box">
			</ul>
			<input type="hidden" name="user_id" id="user_id" value="0"/>
                                         </div>
                                        <div class="col-xs-5">
											<span style="color:green;display: none;" id="add_user">该用户可以添加</span>
					                          <!--<span style="color:#ff9800;">（普通但必须平台用户，特殊单无需平台用户。）</span>-->
                                         </div> 
                                     </div>
                                    </td>
                                </tr>
                                <tr id="dai">
                                    <td>收货人:</td>
                                    <td>
                                    <div class="form-group ">
	                                    <div class="col-xs-2">
	                                        <input name="consignee" id="consignee" value="{$order.consignee}" class="form-control" placeholder="收货人名字"/>	                                    
                                        </div>
                                        <div class="col-xs-2">
										    <span id="err_consignee" style="color:#F00; display:none;">收货人名字不能为空</span>
                                        </div>
                                    </div>    
                                    </td>
                                </tr>
                                <tr id="dai">
                                    <td>地址:</td>
                                    <td>
                                    <div class="form-group ">
                                        <div class="col-xs-4">
                                        <input name="address" id="address" value="{$order.address}" class="form-control"   placeholder="详细地址" readonly="readonly"/>
									    </div>
										<div class="col-xs-2">
										    <span id="err_address" style="color:#F00; display:none;">请完善收货地址</span>
                                        </div>
									</div>  
                                    </td>
                                </tr>
                                <tr id="dai">
                                    <td>手机:</td>
                                    <td>
                                    <div class="form-group ">
	                                    <div class="col-xs-2">
	                                        <input name="mobile" id="mobile" value="{$order.mobile}" class="form-control" placeholder="收货人联系电话" readonly="readonly"/>
                                        </div>
										<div class="col-xs-2">
										    <span id="err_mobile" style="color:#F00; display:none;">收货人电话不能为空</span>
                                        </div> 
                                    </div>    
                                    </td>
                                </tr>
                               <tr id="teshu">
                                    <td>物流线路:</td>
                                    <td>
                                    <div class="form-group ">
	                                    <div class="col-xs-1">
	                                        <input name="biaoshi_xian" id="biaoshi_xian" value="" class="form-control" placeholder="线路" readonly="readonly"/>
                                        </div><div class="col-xs-2">
										    <span id="err_biaoshi_xian" style="color:#F00; display:none;">线路不能为空</span>
                                        </div> <span style="color:#ff9800;">（不清楚可咨询平台客服。）</span>
                                    </div>
                                    </td>
                                </tr>
<!--                           <tr id="teshu" style="color:unset;">
                                    <td>特殊附件:</td> 
							<td>
							<div class="goods_xc" style="width:70px; text-align:center; margin: 5px; display:inline-block;">
								<input type="hidden" name="fujian" id="fujian" value="">
								<a href="javascript:void(0);" onclick="GetUploadify(1,'','goods','call_back2');">
									<img src="/Public/images/add-button.jpg" width="70" height="70"></a>
								<br>
								<a href="javascript:void(0)">&nbsp;&nbsp;</a>
							</div>  <span style="color:#999;">（选填，可上传实际单据）</span>
							</td>
                            </tr> -->
                               <tr>
                                    <td>添加商品:</td>
                                    <td>
                                        <div class="form-group">
                                            <div class="col-xs-2">
	                                            <a class="btn btn-primary" href="javascript:void(0);" onclick="selectGoods()" ><i class="fa fa-search"></i>添加商品</a>
                                            </div> 
                                            <div class="col-xs-2">
                                                <span id="err_goods" style="color:#F00; display:none;">请添加下单商品</span>
                                            </div>
                                        </div>
                                    </td>
                                </tr>
                               <tr>
                                    <td>商品:</td>
                                    <td> 
                                       <div class="form-group"> 
                                            <div class="col-xs-10">
                                                <table class="table table-bordered">
                                                    <thead>
                                                    <tr>
                                                        <td class="text-left">商品名称</td>
                                                        <td class="text-left">价格</td>
                                                        <td class="text-left">库存</td>
                                                        <td class="text-left">购买数量</td>
                                                        <td class="text-left">操作</td>
                                                    </tr>
                                                    </thead>
                                                    <tbody id="goods_td">
                                                    </tbody>
												</table>
                                            </div>
	                                   </div>
                                    </td>
                                </tr>
                               <tr id="teshu">
                                    <td>特殊单金额:</td>
                                    <td>
                                    <div class="form-group "> 
	                                    <div class="col-xs-2">
	                                        <input name="z_jine" id="z_jine" type="number" value="0" class="form-control" placeholder="总金额" style="width:120px;"/> 
                                        </div><div class="col-xs-2">
										    <span id="err_z_jine" style="color:#F00; display:none;">总金额为空</span>
                                        </div> 
                                    </div>
                                    </td>
                                </tr>
								<tr id="teshu">
								     <td>单号:</td>
								     <td>
								     <div class="form-group "> 
								         <div class="col-xs-4">
								             <input name="order_sn" id="order_sn" type="text" value="" class="form-control" placeholder="线下单号"/> 
								         </div><div class="col-xs-2">
											<span id="err_order_sn" style="color:#F00; display:none;">线下单号为空</span>
								         </div> 
								     </div>
								     </td>
								 </tr>
								 <tr id="teshu">
								      <td>标签数:</td>
								      <td>
								      <div class="form-group "> 
								          <div class="col-xs-1">
								              <input name="biaoqian" id="biaoqian" type="number" value="0" class="form-control" placeholder="标签数"/> 
								          </div><div class="col-xs-2">
								 			<span id="err_biaoqian" style="color:#F00; display:none;">标签数不能为空</span>
								          </div> 
								      </div>
								      </td>
								  </tr>
                               <tr>
                                    <td>单据备注:</td>
                                    <td>
                                    <div class="form-group ">
	                                    <div class="col-xs-8">
                                        	<textarea style="width:100%; height:150px;" class="ckeditor" name="user_note" id="user_note"></textarea>
											<span id="err_user_note" style="color:#F00; display:none;">特殊单据备注不能为空</span>
                                        </div>
                                    </div>    
                                    </td>
                                </tr>
                                
                                </tbody>
                                </table>
                        </div>
                        <input type="hidden" name="id" value="{$order.order_id}">
                        <button class="btn btn-info" type="button" onclick="checkSubmit()">
                            <i class="ace-icon fa fa-check bigger-110"></i>
                            保存
                        </button>
                    </form>
<!--以下是在线编辑器 代码 -->
<script type="text/javascript">
    /*
	 * 在线编辑器相 关配置 js
	 *  参考 地址 http://fex.baidu.com/ueditor/
	 */
    // 上传商品相册回调函数
    function call_back2(paths){
            $(".goods_xc").find('img').attr('src',paths);// 修改他的图片路径
            $(".goods_xc").find('a:eq(1)').attr('onclick',"ClearPicArr2(this)").text('删除');
            $(".goods_xc").find('#fujian').val('{$myurl}'+paths); // 设置隐藏域 要提交的值
    }
	    function ClearPicArr2(obj)
	    {
	        $(obj).parent().find('img').attr('src','/Public/images/add-button.jpg'); // 删除完服务器的, 再删除 html上的图片
			$(".goods_xc").find('#fujian').val('');
		}
	
    window.UEDITOR_Admin_URL = "__ROOT__/Public/plugins/Ueditor/";
    var URL_upload = "https://{:$_SERVER['HTTP_HOST']}{$URL_upload}";
    var URL_fileUp = "http://{:$_SERVER['HTTP_HOST']}{$URL_fileUp}";
    var URL_scrawlUp = "http://{:$_SERVER['HTTP_HOST']}{$URL_scrawlUp}";
    var URL_getRemoteImage = "http://{:$_SERVER['HTTP_HOST']}{$URL_getRemoteImage}";
    var URL_imageManager = "http://{:$_SERVER['HTTP_HOST']}{$URL_imageManager}";
    var URL_imageUp = "http://{:$_SERVER['HTTP_HOST']}{$URL_imageUp}";
    var URL_getMovie = "http://{:$_SERVER['HTTP_HOST']}{$URL_getMovie}";
    var URL_home = "http://{:$_SERVER['HTTP_HOST']}{$URL_home}";
</script>
<script type="text/javascript" charset="utf-8" src="__ROOT__/Public/plugins/Ueditor/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="__ROOT__/Public/plugins/Ueditor/ueditor.all.min.js"> </script>
<script type="text/javascript" charset="utf-8" src="__ROOT__/Public/plugins/Ueditor/lang/zh-cn/zh-cn.js"></script>
<script>
    var editor;
    $(function () {
        //具体参数配置在  editor_config.js  中
        var options = {
            zIndex: 999,
            initialFrameWidth: "95%", //初化宽度
            initialFrameHeight: 220, //初化高度
            focus: false, //初始化时，是否让编辑器获得焦点true或false
            maximumWords: 99999, removeFormatAttributes: 'class,style,lang,width,height,align,hspace,valign'
            , //允许的最大字符数 'fullscreen',
            pasteplain:false, //是否默认为纯文本粘贴。false为不使用纯文本粘贴，true为使用纯文本粘贴
            autoHeightEnabled: true,
        	toolbars: [
                   ['fullscreen', 'source', '|', 'undo', 'redo',
                       '|', 'bold', 'italic', 'underline', 'fontborder',
                       'strikethrough', 'superscript', 'subscript',
                       'removeformat', 'formatmatch', 'autotypeset',
                       'blockquote', 'pasteplain', '|', 'forecolor',
                       'backcolor', 'insertorderedlist',
                       'insertunorderedlist','selectall', 'cleardoc']
               ]
        };
        editor = new UE.ui.Editor(options);
        editor.render("user_note");  //  指定 textarea 的  id 为 goods_content

<?php 
if($action){
	echo "$('input:radio[name=dai_type]')[1].click();";
}
?>
    }); 
	
						$('input:radio').click(function(){
						    var zhi=$(this).val();
							$("span[id^='err_']").each(function(){
								$(this).hide();
							});
							$('#add_user').hide(100);
							if(zhi==1){
								//$('#address').removeAttr('readonly');$('#address').val('');
								//$('#mobile').removeAttr('readonly');$('#mobile').val('');
								$('#biaoshi_xian').removeAttr('readonly');$('#biaoshi_xian').val('');$('#user_name').val('');$('body #teshu').show(200);$('body #dai').hide(200);
							}else{
								//$('#address').attr('readonly','readonly');
								//$('#mobile').attr('readonly','readonly');
								$('#biaoshi_xian').attr('readonly','readonly');
								$('body #teshu').hide(100);$('body #dai').show(200);
							}
							
						  });
						  
                        function checkSubmit()
						{
                            if($('#user_id').val()==0){
                                layer.alert('请选择用户', {icon: 2});
                                return false;
                            }
							var dai_type=$("input[type='radio']:checked").val();
							$("span[id^='err_']").each(function(){
								$(this).hide();
							});
							
							//if(dai_type=='1')
								//($.trim($('#user_note').val()) == '') && $('#err_user_note').show();
	
						   ($.trim($('#order_sn').val()) == '') && $('#err_order_sn').show();
						   ($.trim($('#biaoshi_xian').val()) == '') && $('#err_biaoshi_xian').show();
						   ($.trim($('#biaoqian').val()) == '0') && $('#err_biaoqian').show();
						   //($.trim($('#mobile').val()) == '') && $('#err_mobile').show();
						   if(dai_type=='0')
						   ($("input[name^='goods_id']").length ==0) && $('#err_goods').show();
						   
						   if($("span[id^='err_']:visible").length > 0 ) 
						      return false;

							$('#order-add').submit();
						}
                    </script>
                </div>
            </div>
            
        </div>    <!-- /.content -->
    </section>
</div>
<script>
    var timer;
	function kehu_sousuo(obj)
	{

        if (timer) {
            clearTimeout(timer);
        }

        timer = setTimeout(function() {
            var value = obj.val();
            if($.trim(user_name) == '')
                return false;

            var dai_type=$("input[type='radio']:checked").val();
            $.ajax({
                type : "POST",
                url:"/index.php?m=seller&c=User&a=search_user",//+tab,
                data :{search_key:value,dai_type:dai_type,store_id:{$store_id}},
                success: function(data){
                    data=JSON.parse(data);
                    if(data.code=='200'){
                        $('#fenlei_box').show(200);
                        $('#add_user').hide(100);
                        $('#fenlei_box').html(data.selects);
                    }else{
                        $('#fenlei_box').hide(100);
                        if(dai_type==2)
                            $('#add_user').show(200);

                        $('#fenlei_box').html('');
                    }
                }
            });
        }, 800);

	}

    /* 用户客户选择 layer.msg('该用户不是本商城审核会员！不能代其下单。', {icon: 5});*/
    $(document).ready(function(){
		$("body").on("click", function() {
			$('#fenlei_box').hide(100);
		});
		
		$("#fenlei_box").on("click","li", function() {
			var user_id=$(this).attr('rel'),
				consignee=$(this).attr('alt'),
				address=$(this).attr('class'),
				company=$(this).attr('title'),
				biaoshi_xian=$(this).attr('id'),
				shouji=$(this).attr('rev');

			$('#consignee').val(consignee);
			$('#address').val(address);
			$('#mobile').val(shouji);
			$('#biaoshi_xian').val(biaoshi_xian);
			$('#user_name').val(company);
			$('#user_id').val(user_id);
		});
	
	$("#goods_td").on("change","input", function() {
		tongji();
	});
	
	$("#goods_td").on("click","a", function() {
		$(this).parent().parent().remove();
		tongji();
    })
	})
// 选择商品
function selectGoods(){
    var url = "{:U('Seller/Order/search_goods')}";
    
var isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
 
if (isMobile) {
    // 是手机设备
   var width = '90%';
} else {
   var width = '60%';
}
    layer.open({
        type: 2,
        title: '选择商品',
        shadeClose: true,
        shade: 0.8,
        area: [width, width],
        content: url, 
    });
}
// 选择商品返回
function call_back(table_html)
{ 	//console.log(table_html);
	//$('#goods_td').empty().html('<table class="table table-bordered">'+table_html+'</table>');
	//table_html=table_html.replaceAll("javascript:$(this).parent().parent().remove();","");console.log(table_html);
	$('#goods_td').append(table_html);
	layer.closeAll('iframe');tongji();
}
function tongji(){
	var heji=0;
	$("#goods_td tbody tr").each(function(){
		var price=$(this).find('td').eq(1).text();
		var num=$(this).find('input').val();
		if(price!=''){
			price=parseFloat(price);num=parseFloat(num);
			heji=heji+(price*num);
		}
	  });
	  $('#z_jine').val(heji.toFixed(3));
	 //return heji.toFixed(3);
}
</script>
</body>
</html>